/*
 * @Project Name: spring-boot
 * @File Name: UploadController
 * @Package Name: com.hhly.spring.boot.cache.controller
 * @Date: 2018/6/16 14:45
 * @Creator: linshixing-1199
 * @line------------------------------
 * @修改人:
 * @修改时间:
 * @修改内容:
 */

package com.sm.shoplook.controller.system;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.google.common.collect.Maps;
import com.sm.shoplook.util.FileUtil;

/**
 * @author chenpy-1072
 * @desc UploadController
 * @date 2018/6/16 14:45
 * @see
 */
@Controller
public class UploadController {

	@Autowired
	private FileUtil fileUtil;

	/**
	 * 上传图片
	 * @param upfile
	 * @return
	 */
	@RequestMapping(value = "/upload")
	@ResponseBody
	public Map<String, String> uploadFile(@RequestParam MultipartFile upfile) {
		Map<String, String> map = Maps.newHashMap();
		String fileName = fileUtil.uploadFile(upfile);
		map.put("url", fileName);
		map.put("original", upfile.getOriginalFilename());
		map.put("state", "SUCCESS");
		map.put("msg", "SUCCESS");
		return map;
	}
}
